/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.tue.nl.aa;

import java.util.ArrayList;

/**
 * Class to represent a machine in the (Greedy-)Ordered Scheduling Algorithm.
 * @author waldo
 */
public class MachineDTO implements Comparable<MachineDTO> {
    
    private ArrayList<JobDTO> a_i;
    private long tl;
    private int index;
    
    /**
     * Constructor. Prepares the machine to receive {@link JobDTO}'s.
     */
    public MachineDTO(){
        a_i = new ArrayList<JobDTO>();
        tl = 0;
        index = -1;
    }
    
    /**
     * @param job to add to this machine.
     */
    public void addJob( JobDTO job ){
        a_i.add(job);
        tl+=job.getTime();
    }
    /**
     * @param i , index of the specified job in the machine.
     * @return The needed time to complete job i.
     */
    public long getJobTime( int i ){ return a_i.get( i ).getTime(); }
    /**
     * @return amount of jobs in the machine.
     */
    public int getAmountOfJobs(){ return a_i.size(); }
    /**
     * @return Time load for this machine.
     */
    public long getTimeLoad(){ return tl; }
    /**
     * Set the index id for the machine in the set of machines.
     * @param id , index for the machine in the set of machines.
     */
    public void setIndex(int id){ index = id;}
    /**
     * @return Index for the machine in the set of machines.
     */
    public int getIndex(){ return index; }

    /**
     * Implementation of Comparable.
     */
    @Override public int compareTo(MachineDTO machine) {
        if( this.getTimeLoad()<machine.getTimeLoad() ) return -1;
        else if( this.getTimeLoad()>machine.getTimeLoad() ) return 1;
        else return 0;
    }

    /**
     * @return Amount of jobs, and the time load in this machine.
     */
    @Override public String toString(){
        return "MachineDTO ("+index+"). Amount of jobs: "+a_i.size()
                +", time load: "+tl+"\n";
    }
    
}
